package com.situ.mall.service.impl;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mall.common.ServerResponse;
import com.situ.mall.dao.UserMapper;
import com.situ.mall.entity.Product;
import com.situ.mall.entity.User;
import com.situ.mall.service.IUserService;

@Service
public class UserServiceImpl implements IUserService{
	@Autowired
	private UserMapper userMapper;

	@Override
	public ServerResponse login(String username, String password, HttpSession session) {
		User user = userMapper.login(username, password);
		if (user != null) {
			session.setAttribute("user", user);
			return ServerResponse.createSuccess("登录成功");
		}
		return ServerResponse.createError("登录失败");
	}

	@Override
	public ServerResponse pageList(Integer page, Integer limit, User user) {
		PageHelper.startPage(page, limit);
		List<User> list = userMapper.pageList(user);
		PageInfo pageInfo = new PageInfo(list);
		int count = (int) pageInfo.getTotal();
		return ServerResponse.createSuccess("", count, list);
	}


}
